package main.flex.business
{
	import mx.rpc.AsyncToken;
	import mx.rpc.remoting.RemoteObject;
	
	import org.servebox.foundry.service.AbstractBusinessDelegate;
	import org.servebox.foundry.service.IBusinessDelegate;
	import org.servebox.foundry.service.IBusinessResponder;

	public class MainBusinessDelegate extends AbstractBusinessDelegate implements IBusinessDelegate
	{
		// implémentation de design pattern -> Singleton
		private static var _mainInstance : MainBusinessDelegate;
		
		
		// implémentation de design pattern -> Singleton
		public static function getInstance() : MainBusinessDelegate
		{
			if ( _mainInstance == null )
			{
				_mainInstance = new MainBusinessDelegate();
			}
			return _mainInstance;
		}
		
		// à la création de l'instance, on référence le service
		public function MainBusinessDelegate( service : Object = null )
		{
			super( service );
		}
		
		// lie un Responder à l'appel du service
		protected function linkResponderToCall( token : Object, responder : IBusinessResponder ):void
		{
			linkResponderToCallToken( AsyncToken( token ), responder );
			// AsyncToken( token ).addResponder( responder );
		}
		
		/////////////////////////////////////////////////////////////////////////////
		// méthode d'exemple d'appel à AMF avec ajout du responder
		/*
		
		public function my_Method_Also_Referenced_Into_My_AMFPHP_Service( responder : IBusinessResponder ) : void
		{
			linkResponderToCall( AMFPHPFacade().my_Method_Also_Referenced_Into_My_AMFPHP_Service() as Object, responder );
		}
		
		*/
		public function getSessionInfo( responder : IBusinessResponder ) : void
		{
			linkResponderToCall( AMFPHPFacade().getSessionInfo() as Object, responder );
		}
		
		public function connectUser( responder : IBusinessResponder, login : String, mdp : String ) : void
		{
			linkResponderToCall( AMFPHPFacade().connectUser(login, mdp) as Object, responder );
		}
		
		public function getMedia( responder : IBusinessResponder, espaceId : int ) : void
		{
			var param : String = espaceId.toString();
			linkResponderToCall( AMFPHPFacade().getMedia( param ) as Object, responder );
		}
		/////////////////////////////////////////////////////////////////////////////
		
		public function AMFPHPFacade() : RemoteObject
		{
			return RemoteObject( getService() );
		}
		
		
	}
}